import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution539 {
    public int findMinDifference(List<String> timePoints) {
        if (timePoints.size()>1440){
            return 0;
        }
        Collections.sort(timePoints,(a,b)->{
            int ah=Integer.parseInt(a.substring(0,2));
            int bh=Integer.parseInt(b.substring(0,2));
            int am=Integer.parseInt(a.substring(3));
            int bm=Integer.parseInt(b.substring(3));
            if (ah!=bh){
                return ah-bh;
            }else{
                return am-bm;
            }
        });
        int min=Integer.MAX_VALUE;
        timePoints.add(timePoints.get(0));
        for (int i=0;i<timePoints.size()-1;i++){
            String a=timePoints.get(i);
            String b=timePoints.get(i+1);
            int ah=Integer.parseInt(a.substring(0,2));
            int bh=Integer.parseInt(b.substring(0,2));
            int am=Integer.parseInt(a.substring(3));
            int bm=Integer.parseInt(b.substring(3));
            int count=(bh-ah)*60+bm-am;
            if (i==timePoints.size()-2){
                count+=24*60;
            }
            min=Math.min(min,count);
        }
        return min;
    }

    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("00:00");
        list.add("23:59");
        System.out.println(new Solution539().findMinDifference(list));
    }
}
